﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RazorEngine;
using BussinesLayer.Services;
using DataAccess.Datatypes;

namespace Mvc4.Controllers
{
    public class StyleController : Controller
    {
        //
        // GET: /Style/

        public string Index(int id)
        {
            //TODO:leer id del sitio elegido del ViewBag, recuperar los valores de configuración del sitio y asignarlo en la variable model
            SiteServices ss = new SiteServices();

            Site data = ss.GetSite(id);

            string[] parametros =  data.Style.Split(',');

            string fontText;
            string fontTitle;

            if (!getFonts().TryGetValue(Int16.Parse(parametros[5]), out fontText)) 
            {
                fontText = "sans-serif";
            }

            if (!getFonts().TryGetValue(Int16.Parse(parametros[8]), out fontTitle))
            {
                fontTitle = "sans-serif";
            }
            var model = new
            {
                btnPrimaryColor = parametros[0],
                btnSecondaryColor = parametros[1],
                btnOverColor = parametros[2],
                btnOverBackg = parametros[3],
                fontTextColor = parametros[4],
                fontTextFamily = fontText,
                fontTextOverColor = parametros[6],
                fontTitleColor = parametros[7],
                fontTitleFamily = fontTitle,
                fontTitleOverColor = parametros[9],
                imgCalendar = parametros[10],
                fontCarrColor= parametros[11]
            };
            Response.ContentType = "text/css";
            return Razor.Parse(System.IO.File.ReadAllText(Server.MapPath("/Content/DinamicSite.css")), model);
        }

        public static Dictionary<int, string> getFonts()
        {
            Dictionary<int, string> items = new Dictionary<int, string>();
            //items.Add(0,new  { Text = "Georgia, serif", Value = "0" });
            //items.Add(new  { Text = "Arial, Helvetica, sans-serif", Value = "1" });
            //items.Add(new  { Text = "Impact, Charcoal, sans-serif", Value = "2" });
            //items.Add(new  { Text = "Tahoma, Geneva, sans-serif", Value = "3" });
            //items.Add(new  { Text = "Verdana, Geneva, sans-serif", Value = "4" });


            // items.Add(new SelectListItem { Text = "\"Palatino Linotype\", "Book Antiqua", Palatino, serif", Value = "0" });
            // items.Add(new SelectListItem { Text = ""Times New Roman", Times, serif", Value = "2", Selected = true });
            //items.Add(new SelectListItem { Text = ""Arial Black", Gadget, sans-serif", Value = "3" });
            //items.Add(new SelectListItem { Text = ""Comic Sans MS", cursive, sans-serif", Value = "3" });
            //items.Add(new SelectListItem { Text = ""Lucida Sans Unicode", "Lucida Grande", sans-serif", Value = "3" });
            //items.Add(new SelectListItem { Text = ""Trebuchet MS", Helvetica, sans-serif", Value = "3" });
            //  items.Add(new SelectListItem { Text = ""Courier New", Courier, monospace", Value = "3" });
            //items.Add(new SelectListItem { Text = ""Lucida Console", Monaco, monospace", Value = "3" });

            items.Add(0, "Georgia, serif");
            items.Add(1, "Arial, Helvetica, sans-serif");
            items.Add(2, "Impact, Charcoal, sans-serif");
            items.Add(3, "Tahoma, Geneva, sans-serif");
            items.Add(4, "Verdana, Geneva, sans-serif");
            return items;

        }
    }
}
